#include <iostream>
using namespace std;
/*
友元函数
1、友元函数
2、友元类
3、友元成员函数

*/

class B
{
private:
    int b;
    friend class A;
public:
    B():b(20)
    {

    }
    void printf();
};

class C
{
private:
    int c;
    friend void B::printf();
public:
    C():c(30)
    {

    }
    void hello();
};


class A
{
private:
    int a;
public:
    A():a(10)
    {

    }
    void printB();
    friend void print(); //友元函数
    friend class B;    //有元类
    friend void C::hello(); //有元成员函数
};

void print()
{
    A a1;
    cout<<a1.a<<endl;
}


int main()
{
    B b0;
    b0.printf();

    return 0;
}

void A::printB()
{
    B b1;
    cout<<b1.b<<endl;
}

void C::hello()
{
    A a3;
    cout<<"hello"<<a3.a<<endl;
}

void B::printf()
{
    A a2;
    cout<<a2.a<<endl;
    B b2;
    cout<<b2.b<<endl;
    C c1;
    cout<<c1.c<<endl;
}
